package com.baizan.daka.ui.presenter

import com.baizan.daka.base.BasePresenter
import com.baizan.daka.mvp.model.MeModel
import com.baizan.daka.ui.contract.LoginContract
import com.baizan.daka.mvp.model.UserModel
import com.baizan.daka.mvp.model.bean.BankCardInfoBean
import com.baizan.daka.mvp.model.bean.LoginInfoBean
import com.baizan.daka.rx.Subscriber.CommonSubscriber
import com.baizan.daka.showToast
import com.baizan.daka.ui.contract.SettingContract
import com.baizan.daka.util.Md5

class LoginOutPresenter(val mView: SettingContract.View) : BasePresenter(),
    SettingContract.Presenter {


    private val userModel: UserModel by lazy {
        UserModel()
    }

    private val meModel: MeModel by lazy {
        MeModel()
    }

    override fun loginOut() {
        mView.showLoadingDialog()
        userModel.loginOut()//+"baiwandianzanmima"
            .subscribe(object : CommonSubscriber<Any>(compositeDisposable) {

                override fun onCallNext(t: Any?) {
                    mView.loginOutSuccess()
                }

                override fun onCallError(e: String) {
                    super.onCallError(e)
                    showToast(e)
                }

                override fun onCallCompleted() {
                    super.onCallCompleted()
                    mView.hideLoadingDialog()
                }

            })
    }

    override fun getBankInfo() {
        mView.showLoadingDialog()
        meModel.getBankCard()
            .subscribe(object : CommonSubscriber<BankCardInfoBean>(compositeDisposable) {

                override fun onCallNext(t: BankCardInfoBean?) {
                    mView.getBankInfoSuccess(t)
                }

                override fun onCallError(e: String) {
                    super.onCallError(e)
                    mView.getBankInfoFail()
                }

                override fun onCallCompleted() {
                    super.onCallCompleted()
                    mView.hideLoadingDialog()
                }
            })

    }
}

